import Helper from '../../lib'
import _ from 'lodash'
const namespaced = true
const state = {
  tree: [
    // {
    //   type: 'up',
    //   name: 'Verify',
    //   locked: true,
    // },
  ],
}

const mutations = {
  PUSH(state, data) {
    if (Helper.isType(data, {})) {
      state.tree.push(_.cloneDeep(data))
    } else if (Helper.isType(data, [])) {
      state.tree = state.tree.concat(_.cloneDeep(data))
    } else {
      state.tree.push(_.cloneDeep({
        type: 'slide-right',
        name: data,
        config: {},
        param: {},
      }))
    }
  },
  REPLACE(state, data) {
    if (Helper.isType(data, {})) {
      state.tree = [_.cloneDeep(data)]
    } else if (Helper.isType(data, [])) {
      state.tree = [].concat(data)
    } else {
      state.tree = [_.cloneDeep({
        type: 'slide-right',
        name: data,
        config: {},
        param: {},
      })]
    }
  },
  POP(state) {
    state.tree.pop()
  },
  CLOSE(state) {
    state.tree = []
  },
}

const actions = {
  push({commit}, data) {
    commit('PUSH', data)
  },
  replace({commit}, data) {
    commit('REPLACE', data)
  },
  pop({commit}) {
    commit('POP')
  },
  close({commit}) {
    commit('CLOSE')
  },
}

export default {
  namespaced,
  state,
  mutations,
  actions,
}
